From 9ca7977d4357b7225eda2e528ad6053e126b32de Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 24 Jul 2009 15:26:37 +0000 Subject: [PATCH] Apply Paul Cornett's other patch to fix timeouts on PN-20. --- delbin.c | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/delbin.c b/delbin.c index ce33830f4..6ca3858b1 100644 --- a/delbin.c +++ b/delbin.c @@ -73,6 +73,9 @@ static unsigned delbin_os_packet_size; // number of times to attempt a transfer before giving up #define ATTEMPT_MAX 2 +// seconds to wait for expected message, this value is 1 greater than +// minimum, i.e. READ_TIMEOUT - 1 <= actual_timeout <= READ_TIMEOUT +#define READ_TIMEOUT 6 // debug output: low, medium, high, higher #define DBGLVL_L 1 @@ -396,7 +399,7 @@ debug_out_time(const char* s) gettimeofday(&tv, NULL); debug_out("%u.%03u %s", (unsigned)tv.tv_sec & 0xf, (unsigned)tv.tv_usec / 1000, s); #else - debug_out("%s", s); + debug_out("%u %s", (unsigned)time(NULL) & 0xf, s); #endif } @@ -448,27 +451,27 @@ packet_read(void* buf) } static void -packet_write(const void* p, unsigned size) +packet_write(const void* buf, unsigned size) { unsigned n; if (global_opts.debug_level >= DBGLVL_H) { unsigned j; - const gbuint8* pp = p; + const gbuint8* p = buf; debug_out_time("pcktwr"); for (j = 0; j < size; j++) { - warning(" %02x", pp[j]); + warning(" %02x", p[j]); } if (global_opts.debug_level >= DBGLVL_H2) { warning(" "); for (j = 0; j < size; j++) { - int c = pp[j]; + int c = p[j]; warning("%c", isprint(c) ? c : '.'); } } warning("\n"); } - n = delbin_os_ops.packet_write(p, size); + n = delbin_os_ops.packet_write(buf, size); if (n != size) { fatal(MYNAME ": short write %u %u\n", size, n); } @@ -686,13 +689,12 @@ message_ack(unsigned id, const message_t* m) } // Get specific message, ignoring others. Sends ACK for non-interval messages. -// Gives up if 6 navigation messages are received, which means we waited at least -// 5 seconds. +// Gives up after at least READ_TIMEOUT-1 seconds have passed. static int message_read(unsigned msg_id, message_t* m) { unsigned id; - int interval_message_count = 0; + time_t time_start = time(NULL); if (global_opts.debug_level >= DBGLVL_M) warning(MYNAME ": looking for %x\n", msg_id); @@ -702,15 +704,9 @@ message_read(unsigned msg_id, message_t* m) break; } message_ack(id, m); - if (id == msg_id) { + if (id == msg_id || time(NULL) - time_start >= READ_TIMEOUT) { break; } - if (id == MSG_NAVIGATION) { - interval_message_count++; - if (interval_message_count == 6) { - break; - } - } } return id == msg_id; } @@ -727,7 +723,7 @@ get_batch(message_t** array, unsigned* n) if (global_opts.debug_level >= DBGLVL_M) warning(MYNAME ": begin get_batch\n"); do { - unsigned timeout_count = 0; + time_t time_start = time(NULL); if (i == array_max) { message_t* old_a = a; array_max += array_max; @@ -740,13 +736,11 @@ get_batch(message_t** array, unsigned* n) id = message_read_1(0, &a[i]); switch (id) { case MSG_NAVIGATION: - timeout_count++; - if (timeout_count == 6) { + if (time(NULL) - time_start >= READ_TIMEOUT) { success = 0; break; } // fall through - case 0: case MSG_ACK: case MSG_NACK: case MSG_SATELLITE_INFO: @@ -818,6 +812,8 @@ send_batch(int expect_transfer_complete) warning(MYNAME ": begin send_batch, %u messages\n", n); for (i = 0; i < n; i++) { unsigned timeout_count = 0; + time_t time_start = time(NULL); + message_write(batch_array[i].msg_id, &batch_array[i].msg); for (;;) { unsigned id = message_read_1(0, &m); @@ -825,17 +821,17 @@ send_batch(int expect_transfer_complete) case MSG_ACK: break; case MSG_NAVIGATION: - timeout_count++; - if (timeout_count > 2) { - fatal(MYNAME ": send_batch timed out\n"); - } - if (timeout_count == 2) { + if (time(NULL) - time_start >= 2) { + if (timeout_count) { + fatal(MYNAME ": send_batch timed out\n"); + } + timeout_count++; if (global_opts.debug_level >= DBGLVL_M) warning(MYNAME ": re-sending %x\n", batch_array[i].msg_id); message_write(batch_array[i].msg_id, &batch_array[i].msg); + time_start = time(NULL); } // fall through - case 0: case MSG_NACK: case MSG_SATELLITE_INFO: continue; @@ -1049,6 +1045,7 @@ get_gc_notes(const waypoint* wp, int* symbol, char** notes, unsigned* notes_size case gt_benchmark: gc_sym = 172; break; case gt_cito: gc_sym = 167; break; case gt_mega: gc_sym = 166; break; + case gt_wherigo: gc_sym = 164; break; case gt_unknown: case gt_locationless: case gt_ape: @@ -2027,7 +2024,7 @@ delbin_list_units() { int i; for (i = 0; i < n_delbin_units; i++) { - printf("%d %s %s\n", + printf("%u %s %s\n", delbin_unit_info[i].unit_number, delbin_unit_info[i].unit_serial_number, delbin_unit_info[i].unit_name ); -- 2.30.2